package com.designpatterns.interpreterpattern;

import com.designpatterns.interpreterpattern.impl.AndExpression;
import com.designpatterns.interpreterpattern.impl.OrExpression;
import com.designpatterns.interpreterpattern.impl.TerminalExpression;

public class InterpreterPatternDemo
{
	// 提前给语言录入信息
	
	// 规则：Robert 和 John 是男性
	public static Expression getMaleExpression()
	{
		// 实例化TerminalExpression
		Expression robert = new TerminalExpression("Robert");
		Expression john = new TerminalExpression("John");
		return new OrExpression(robert, john);
	}

	// 规则：Julie 是一个已婚的女性
	public static Expression getMarriedWomanExpression()
	{
		// 实例化TerminalExpression
		Expression julie = new TerminalExpression("Julie");
		Expression married = new TerminalExpression("Married");
		return new AndExpression(julie, married);
	}

	public static void main(String[] args)
	{
		Expression isMale = getMaleExpression();
		Expression isMarriedWoman = getMarriedWomanExpression();

		System.out.println("John is male? " + isMale.interpret("John"));
		System.out.println("Julie is a married women? " + isMarriedWoman.interpret("Married Julie"));
	}
}
